<#list fileList as fileItem>
    <#if fileItem.current><#assign file=fileItem /></#if>
    <#if fileItem.fileName?ends_with("entity.java.ftl")><#assign entityFile=fileItem /></#if>
    <#if fileItem.fileName?ends_with("queryCriteria.java.ftl")><#assign criteriaFile=fileItem /></#if>
    <#if fileItem.fileName?ends_with("mapper.java.ftl")><#assign mapperFile=fileItem /></#if>
    <#if fileItem.fileName?ends_with("service.java.ftl")><#assign iserviceFile=fileItem /></#if>
</#list>
package ${file.packagePath};

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import ${entityFile.packagePath}.${tableInfo.className}${entityFile.summary};
import ${criteriaFile.packagePath}.${tableInfo.className}${criteriaFile.summary};
import ${mapperFile.packagePath}.${tableInfo.className}${mapperFile.summary};
import ${iserviceFile.packagePath}.${tableInfo.className}${iserviceFile.summary};

import java.util.*;

@Service
public class ${tableInfo.className}${file.summary} extends ServiceImpl<${tableInfo.className}${mapperFile.summary}, ${tableInfo.className}${entityFile.summary}> implements ${tableInfo.className}${iserviceFile.summary}  {
    /**
    * 条件查询分页列表
    *
    * @param criteria
    * @return PageR<List<${tableInfo.className}${entityFile.summary}>>
    */
    PageR<List<${tableInfo.className}${entityFile.summary}>> listSearch(${tableInfo.className}${criteriaFile.summary} criteria) {
        LambdaQueryWrapper<${tableInfo.className}${entityFile.summary}> queryWrapper = buildQuery(criteria);
        int total = this.count(queryWrapper);
        queryWrapper.last(String.format("limit %d,%d", (criteria.getPageNo() - 1) * criteria.getPageSize(), criteria.getPageSize()));
        List<${tableInfo.className}${entityFile.summary}> res = this.list(queryWrapper);
        return PageR.build(res, total, criteria.getPageNo(), criteria.getPageSize());
    }

    /**
    * 条件查询全部列表
    *
    * @param criteria
    * @return List<${tableInfo.className}${entityFile.summary}>
    */
    List<${tableInfo.className}${entityFile.summary}> listSearchAll(${tableInfo.className}${criteriaFile.summary} criteria){
        LambdaQueryWrapper<${tableInfo.className}${entityFile.summary}> queryWrapper = buildQuery(criteria);
        return this.list(queryWrapper);
    }


    private LambdaQueryWrapper<${tableInfo.className}${entityFile.summary}> buildQuery(${tableInfo.className}${criteriaFile.summary} criteria) {

        LambdaQueryWrapper<${tableInfo.className}${entityFile.summary}> queryWrapper = new LambdaQueryWrapper<>();
        <#list tableInfo.colInfoList as field>
            <#if field.searchWay!?length lt 1>
                <#continue />
            </#if>
            <#if field.javaColumnType == "boolean">
                <#assign getprefix="is"/>
            <#else>
                <#assign getprefix="get"/>
            </#if>
            <#if field.searchWay == "=">
        Optional.ofNullable(criteria.${getprefix}${field.javaColumnName?cap_first}()).ifPresent(value -> queryWrapper.eq(${tableInfo.className}${entityFile.summary}::${getprefix}${field.javaColumnName?cap_first}, value));
            </#if>
            <#if field.searchWay == "<">
        Optional.ofNullable(criteria.${getprefix}${field.javaColumnName?cap_first}()).ifPresent(value -> queryWrapper.lt(${tableInfo.className}${entityFile.summary}::${getprefix}${field.javaColumnName?cap_first}, value));
            </#if>
            <#if field.searchWay == ">">
        Optional.ofNullable(criteria.${getprefix}${field.javaColumnName?cap_first}()).ifPresent(value -> queryWrapper.gt(${tableInfo.className}${entityFile.summary}::${getprefix}${field.javaColumnName?cap_first}, value));
            </#if>
            <#if field.searchWay == "like">
        Optional.ofNullable(criteria.${getprefix}${field.javaColumnName?cap_first}()).ifPresent(value -> queryWrapper.like(${tableInfo.className}${entityFile.summary}::${getprefix}${field.javaColumnName?cap_first}, value));
            </#if>
        </#list>
        return queryWrapper;
    }
}